package com.liujiahe.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liujiahe.entity.House;
import com.liujiahe.service.IHouseService;
import com.liujiahe.vo.HouseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 刘家贺
 * @since 2022-06-30
 */
@RestController
@RequestMapping("/house")
public class HouseController {

    @Autowired
    IHouseService service;

    // 房屋列表
    @RequestMapping("hList")
    public List<House> hList () {
        List<House> list = service.list();
        return list;
    }
    /*@RequestMapping("hList")
    public Page hList (@RequestBody HouseVO houseVO) {
        Page<House> housePage = new Page<>(houseVO.getPage(), houseVO.getPageSize());
        Page<House> page = service.page(housePage);
        return page;
    }*/

    // 添加信息
    @RequestMapping("add")
    public Integer add(@RequestBody House house) {
        boolean save = service.save(house);
        if (save) {
            return 200;
        } else {
            return 201;
        }
    }

    // 根据id删除
    @RequestMapping("del")
    public Integer del (Integer id) {
        boolean b = service.removeById(id);
        if (b) {
            return 200;
        } else {
            return  201;
        }
    }

}
